package com.samuel.blog.controller.web;

import com.github.pagehelper.PageInfo;
import com.samuel.blog.bean.PageBean;
import com.samuel.blog.controller.BaseController;
import com.samuel.blog.entity.ArticleEntity;
import com.samuel.blog.service.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 前台控制层 - 文章
 *
 * @author kaiji
 * @since 2018-05-24
 */
@Controller("webArticleController")
@RequestMapping("/article")
public class ArticleController extends BaseController {

	private static final long serialVersionUID = -4747829927588961665L;

	private static final Logger __logger = LoggerFactory.getLogger(ArticleController.class);
    private static final String PAGE_PRE = "web/";



    @Resource
    private ArticleService articleService;

    @GetMapping("list"+SUFFIX)
    public String list(HttpServletRequest request, PageBean pageBean) {
        try {
            Map<String, Object> filterMap = new HashMap<>();
            filterMap.put("orderBySql", "sort desc");
            filterMap.put("status", 0);
            filterMap.put("deleteStatus", 0);
            PageInfo<ArticleEntity> articleList = articleService.selectPage(pageBean, filterMap);
            request.setAttribute("articleList", articleList);
        } catch (Exception e) {
            e.printStackTrace();
            __logger.error("获取文章异常: {}", e.getMessage());
        }
        __logger.info("查询文章列表成功!");
        return PAGE_PRE+"article_list";
    }
}
